
var util = require('longbing_card/resource/js/util.js');
App({
    onLaunch: function (res) {
        var that = this;
        //By.jingshuixian   初始化  webSocket Url
        var url = that.siteInfo.siteroot ;
        url = util.getHostname(url);
        that.globalData.wssUrl = 'wss://' + url + '/wss' ;
    },
    onShow: function (res) {
        var that = this;

        wx.getSystemInfo({
            success: res => {
                console.log('手机信息res' + res.model)
                let modelmes = res.model;
                if (modelmes.search('iPhone X') != -1) {
                    that.globalData.isIphoneX = true
                }
            }
        })

        console.log(res, "app onShow 888888888888*******************////////////")

        // is_qr是否是扫名片码进来的 1=>是, 0=>不是
        // is_group是否是群分_享进来的 1=>是, 0=>不是
        // type通过什么内容进来的1=>自定义码, 2=>产品, 3=>动态
        // target_id自定义码, 产品, 动态的 id没有则为0

        if (res.query.to_uid) {
            that.globalData.to_uid = res.query.to_uid;
        }
        if (res.query.form_id) {
            that.globalData.loginParam.is_qr = 0;
        }
        if (res.scene) {
            that.globalData.loginParam.scene = res.scene;
        }
        if (!res.query.form_id || res.query.is_qr == 1) {
            that.globalData.loginParam.is_qr = 1;
        }

        if (res.scene == 1044) {
            that.globalData.loginParam.is_group = 1;
        }

        if (res.scene != 1044) {
            that.globalData.loginParam.is_group = 0;
        }

        if (res.query.custom) {
            that.globalData.loginParam.type = 1;
            that.globalData.loginParam.target_id = res.query.custom;
        }

        if (res.query.type) {
            that.globalData.loginParam.type = res.query.type;
        }

        if (that.globalData.loginParam.type) {
            if (res.query.id) {
                that.globalData.loginParam.target_id = res.query.id;
            }

            if (!res.query.id) {
                that.globalData.loginParam.target_id = 0;
            }
        }

        console.log(that.globalData.loginParam, "app.globalData.loginParam *******************//")

        var timer;
        if (res.scene == 1044) {
            timer = setInterval(function () {
                console.log(res.shareTicket, "onLaunch ========= getShareInfo res.shareTicket")
                wx.getShareInfo({
                    shareTicket: res.shareTicket,
                    complete(res) {
                        console.log(res, "onLaunch ========= getShareInfo res")
                        that.globalData.encryptedData = res.encryptedData;
                        that.globalData.iv = res.iv;
                    }
                })
                console.log(wx.getStorageSync("userid"))
                if (wx.getStorageSync("userid")) {
                    clearInterval(timer);
                }
            }, 1000)
        }

    },
    onHide: function () {
    },
    onError: function (msg) {
        console.log(msg)
    },
    //加载微擎工具类
    util: util,
    //导航菜单，微擎将会自己实现一个导航菜单，结构与小程序导航菜单相同
    //用户信息，sessionid是用户是否登录的凭证
    userInfo: {
        sessionid: null,
    },
    siteInfo: require('siteinfo.js'),


    globalData: {
        isIphoneX: false,
        to_uid: '',
        form_id: '',
        nickName: '',
        encryptedData: '',
        iv: '',
        isStaff: false,
        hasClientPhone: false,
        config: {},
        company: {},
        loginParam: {
            scene: '',
            is_qr: '',
            is_group: '',
            type: '',
            target_id: '',
        },
        wssUrl : '',//webSocket url地址 By.jingshuixian 
        tabBarList: [
            {
                "iconPath": "/longbing_card/resource/icon/icon-card.png",
                "selectedIconPath": "/longbing_card/resource/icon/icon-card-cur.png",
                "type": "toCard",
                "text": "名片"
            },
            {
                "iconPath": "/longbing_card/resource/icon/icon-shop.png",
                "selectedIconPath": "/longbing_card/resource/icon/icon-shop-cur.png",
                "type": "toShop",
                "text": "商城"
            },
            {
                "iconPath": "/longbing_card/resource/icon/icon-news.png",
                "selectedIconPath": "/longbing_card/resource/icon/icon-news-cur.png",
                "type": "toNews",
                "text": "动态"
            },
            {
                "iconPath": "/longbing_card/resource/icon/icon-company.png",
                "selectedIconPath": "/longbing_card/resource/icon/icon-company-cur.png",
                "type": "toCompany",
                "text": "官网"
            }
        ]
    }
});